import type { DatabaseQuery, Interceptor, OllamaRequest, OllamaResponse, QueryResult } from '@/types/ollama'

// Ollama 请求拦截器：添加默认参数
export const ollamaRequestInterceptor: Interceptor<OllamaRequest, OllamaResponse> = {
  onRequest: async config => {
    return {
      ...config,
      options: {
        temperature: 0.7,
        top_p: 0.9,
        ...config.options,
      },
    }
  },
}

// Ollama 响应拦截器：处理响应格式
export const ollamaResponseInterceptor: Interceptor<OllamaRequest, OllamaResponse> = {
  onResponse: async response => {
    // 这里可以添加响应处理逻辑
    return response
  },
}

// Ollama 错误拦截器：统一错误处理
export const ollamaErrorInterceptor: Interceptor<OllamaRequest, OllamaResponse> = {
  onError: async error => {
    console.error('Ollama API Error:', error)
    return error
  },
}

// 数据库请求拦截器：添加查询超时
export const dbRequestInterceptor: Interceptor<DatabaseQuery, QueryResult> = {
  onRequest: async query => {
    return {
      ...query,
      options: {
        timeout: 5000, // 5秒超时
        ...query.options,
      },
    }
  },
}

// 数据库响应拦截器：处理查询结果
export const dbResponseInterceptor: Interceptor<DatabaseQuery, QueryResult> = {
  onResponse: async result => {
    // 这里可以添加结果处理逻辑
    return result
  },
}

// 数据库错误拦截器：统一错误处理
export const dbErrorInterceptor: Interceptor<DatabaseQuery, QueryResult> = {
  onError: async error => {
    console.error('Database Query Error:', error)
    return error
  },
}
